package com.lc.user.express.utils;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;


public abstract class NetworkFlux extends BroadcastReceiver {
    public static final String ACTION = ConnectivityManager.CONNECTIVITY_ACTION;

    @Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
        NetworkInfo mobNetInfo = connectivityManager
                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        onConnectChange((activeNetInfo != null && activeNetInfo.isAvailable() && activeNetInfo
                .isConnected()) || (mobNetInfo != null && mobNetInfo.isAvailable() && mobNetInfo
                .isConnected()));
    }

    protected abstract void onConnectChange(boolean isConnect);
}
